package com.app.controller;

import com.app.entity.Blog;
import com.app.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RequestMapping("app")
@RestController
public class BlogController {
    @Autowired
    private BlogService blogService;

    //@CrossOrigin解决跨域问题
    @CrossOrigin
    @PostMapping(value = "/getAllBlog")
    public ArrayList<Blog> getAllBlog(){
        return blogService.getAllBlog();
    }

    @CrossOrigin
    @PostMapping(value = "/addBlog", params = {"params"})
    public String addBlog(@RequestParam String params){
        return blogService.addBlog(params);
    }

    @CrossOrigin
    //{id}为链接传递的参数；@PathVariable(value = "id")接收参数
    @PostMapping(value = "/getBlog/{id}")
    public Blog getBlog(@PathVariable(value = "id") String id){
        System.out.println("id:"+id);
        return blogService.getBlog(id);
    }
}
